package example.oauth.signature;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class MD5 {
	/**
	 * @param
	 * @return	随机产生字符串长度是否为32位
	 */
	@Override
	public String toString() {

		Random random = new Random();
		// 产生123400至9999999随机数
		String result = String.valueOf(random.nextInt(9876599) + 123400);
		// 进行MD5加密
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(result.getBytes());
			byte b[] = md.digest();
			int i;

			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			result = buf.toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return result;

	}
}
